package com.googlecode.imanager.core.base.style;

import com.googlecode.imanager.client.bridge.style.IBackground;
import com.googlecode.imanager.client.media.Image;
import com.googlecode.imanager.client.style.Color;
import com.googlecode.imanager.client.style.HorzAlignment;
import com.googlecode.imanager.client.style.VertAlignment;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class ComputedBackground implements IBackground, ComputedAttribute<IBackground> {

    protected Color color;
    protected Image image;
    protected Boolean imageHorzRepeat;    
    protected Boolean imageVertRepeat;
    protected HorzAlignment imageHorzAlignment;
    protected VertAlignment imageVertAlignment;

    public void mergeWith(IBackground o){
        if (o == null){
            return;
        }
        if (o.getColor() != null){
            color = o.getColor();
        }
        if (o.getImage() != null){
            image = o.getImage();
        }
        if (o.getImageHorzRepeat() != null){
            imageHorzRepeat = o.getImageHorzRepeat();
        }
        if (o.getImageVertRepeat() != null){
            imageVertRepeat = o.getImageVertRepeat();
        }
        if (o.getImageHorzAlignment() != null){
            imageHorzAlignment = o.getImageHorzAlignment();
        }
        if (o.getImageVertRepeat() != null){
            imageVertAlignment = o.getImageVertAlignment();
        }
    }

    @Override
    public void copyFrom(IBackground o) {
        if (o == null){
            color = null;
            image = null;
            imageHorzRepeat = null;
            imageVertRepeat = null;
            imageHorzAlignment = null;
            imageVertAlignment = null;
        } else {
            color = o.getColor();
            image = o.getImage();
            imageHorzRepeat = o.getImageHorzRepeat();
            imageVertRepeat = o.getImageVertRepeat();
            imageHorzAlignment = o.getImageHorzAlignment();
            imageVertAlignment = o.getImageVertAlignment();
        }
    }

    public Color getColor() {
        return color;
    }

    public Image getImage() {
        return image;
    }

    public Boolean getImageHorzRepeat() {
        return imageHorzRepeat;
    }

    public Boolean getImageVertRepeat() {
        return imageVertRepeat;
    }

    public HorzAlignment getImageHorzAlignment() {
        return imageHorzAlignment;
    }

    public VertAlignment getImageVertAlignment() {
        return imageVertAlignment;
    }
    
}
